package baidu.shortpath;

/**
	State in a map search
*/

import java.util.*;

public class Map_State extends Search_State{

  //city for this state
  private String city;
  
  
  //constructor
  public Map_State(String cname, int lc){
    city=cname;
    localCost=lc;
  }
  //accessor
  public String getCity(){
    return city;
  }
        
  // goalP
  public boolean goalP(Search searcher) { 
    Map_Search msearcher = (Map_Search) searcher;
    String tar=msearcher.getGoal(); // get target city
    return (city.compareTo(tar)== 0);
  }

  // Get_Successors	
  public ArrayList<Search_State> get_Successors (Search searcher) {
    Map_Search msearcher = (Map_Search) searcher;
    Carta map=msearcher.getMap();
    ArrayList<Maplink> links=map.get_Links(city);
    ArrayList<Search_State> succs=new ArrayList<Search_State>();
        
    for (Maplink l: links){
    	String scity;
        if (city.compareTo(l.get_city1())==0) {
        scity=l.get_city2();
        }
        else {
        scity=l.get_city1();};
        succs.add((Search_State)new Map_State(scity,l.get_cost()));
    }
    return succs;
    }
  
  // same_State

  public boolean same_State(Search_State s2) {
    Map_State ms2= (Map_State) s2;
    return (city.compareTo(ms2.getCity())==0);
  }
  

// toString 
    public String toString () {
      return ("Map State: "+city);
    }
    
	
    
}



